/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <fstream>
#include <vector>
#include <chrono>

void bubble_sort(std::vector<int>& a) {
    int n = a.size();
    bool swapped;
    for (int i = 0; i < n - 1; i++) {
        swapped = false;
        for (int j = 0; j < n - i - 1; j++) {
            if (a[j] > a[j + 1]) {
                std::swap(a[j], a[j + 1]);
                swapped = true;
            }
        }
        if (!swapped)
            break;
    }
}

int main() {
    std::vector<std::string> files = {"m1_sorted.txt", "m2_reverse.txt", "m3_shuffle.txt"};
    for (const auto& file : files) {
        std::ifstream f(file);
        std::vector<int> b;
        int temp;
        while (f >> temp) {
            b.push_back(temp);
        }
        auto start = std::chrono::high_resolution_clock::now();
        bubble_sort(b);
        auto end = std::chrono::high_resolution_clock::now();
        auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
        std::cout << file << " " << duration << " milliseconds" << std::endl;
    }
    return 0;
}